package com.bestcem.xm.common.core.exception;

import com.bestcem.xm.common.core.enums.CommonErrorEnum;

/**
 * 自定义service层异常类
 *
 * @author Linked <zhijian.lin@idiaoyan.com>
 * @version v1.0
 * @date 2022/8/2 21:20
 */
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 3200004685293133433L;
    /**
     * 异常类型
     */
    private String type;

    /**
     * 异常代码
     */
    private Integer commonErrorEnum;

    /**
     * 异常信息
     */
    private String errorMessage;

    public ServiceException() {
    }

    public ServiceException(String message) {
        super(message);
        this.errorMessage = message;
    }

    public ServiceException(Throwable throwable, CommonErrorEnum e) {
        super(throwable);
        this.errorMessage = e.getMsg();
        this.commonErrorEnum = e.getCode();
    }

    public ServiceException(Throwable throwable, CommonErrorEnum e, String errorMessage) {
        super(throwable);
        this.errorMessage = errorMessage;
        this.commonErrorEnum = e.getCode();
    }

    public ServiceException(CommonErrorEnum e) {
        this.errorMessage = e.getMsg();
        this.commonErrorEnum = e.getCode();
    }

    public ServiceException(CommonErrorEnum e, String errorMessage) {
        this.errorMessage = errorMessage;
        this.commonErrorEnum = e.getCode();
    }

    public Integer getCommonErrorEnum() {
        return this.commonErrorEnum;
    }

    public void setCommonErrorEnum(Integer commonErrorEnum) {
        this.commonErrorEnum = commonErrorEnum;
    }

    public String getErrorMessage() {
        return this.errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getType() {
        return this.type;
    }

    void setType(String type) {
        this.type = type;
    }

    @Override
    public String getMessage() {
        return this.errorMessage;
    }

    void setMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }
}
